<template>
  <div>
    <Card :bordered="false" dis-hover>
      <Row type="flex" justify="space-between">
        <Col>
          <Row :gutter="16" type="flex">
            <Col class="ivu-mb-16">
              <RadioGroup
                v-model="dayDate"
                type="button"
                @on-change="changeradio(dayDate)"
              >
                <Radio :label="0">昨</Radio>
                <Radio :label="1">今</Radio>
              </RadioGroup>
            </Col>
            <Col class="ivu-mb-16">
              <DatePicker
                :editable="false"
                :options="options"
                type="daterange"
                format="yyyy-MM-dd"
                v-model="datatime"
                @on-change="changeDate(datatime)"
                placeholder="请选择日期"
              ></DatePicker>
            </Col>
            <Col class="ivu-mb-16">
              <Input
                v-model="params.keyword"
                v-width="280"
                @on-enter="askDatas"
                clearable
                @on-clear="askDatass"
                @on-keyup="params.keyword = params.keyword.replace(/[, ]/g, '')"
                placeholder="请输入患者姓名/手机号/微信号/唯一身份"
              ></Input>
            </Col>
            <Col class="ivu-mb-16">
              <!-- <Select v-model="params.patient_diseases_id" filterable multiple placeholder="请选择疾病类型" @on-change="formSize(1)">
                            <OptionGroup :label="item.label" v-for="(item,index) in diseaseslist" :key="index">
                                <Option v-for="it in item.children" :value="it.value" :key="it.value">{{ it.title }}
                                </Option>
                            </OptionGroup>
                        </Select> -->
              <TreeSelect
                v-model="params.patient_diseases_id"
                :data="diseaseslist"
                :placeholder="'请选择疾病类型'"
                clearable
                @on-change="formSize(1)"
              ></TreeSelect>
            </Col>
            <Col class="ivu-mb-16">
              <Select
                v-model="params.patient_status_id"
                placeholder="患者状态"
                element-id="diagnosis"
                :clearable="true"
                @on-change="formSize(1)"
              >
                <Option
                  v-for="(item, index) in patientstatusList"
                  :key="index"
                  :value="item.value"
                  >{{ item.label }}</Option
                >
              </Select>
            </Col>
            <Col class="ivu-mb-16">
              <Select
                v-model="params.dialog_mode_id"
                placeholder="对话来源"
                element-id="dialogueSource"
                :clearable="true"
                @on-change="formSize(1)"
              >
                <Option
                  v-for="(item, index) in dialogmodeList"
                  :key="index"
                  :value="item.value"
                  >{{ item.label }}</Option
                >
              </Select>
            </Col>
            <Col class="ivu-mb-16">
              <TreeSelect
                v-model="params.source_channel_id"
                :data="channelList"
                :placeholder="'渠道来源'"
                clearable
                multiple
                @on-change="formSize(1)"
              ></TreeSelect>
              <!-- <Select v-model="params.source_channel_id" placeholder="渠道来源" element-id="channelSource"
                            :clearable="true" @on-change="formSize(1)">
                            <Option v-for="(item, index) in channelList" :key="index" :value="item.id">{{ item.label }}
                            </Option>
                        </Select> -->
            </Col>
            <Col class="ivu-mb-16">
              <!-- <Select v-model="params.area_code" placeholder="请输入城市" filterable remote clearable
                        :remote-method="remoteMethod" @on-change="askData" :loading="loadingcity">
                        <Option v-for="(item, index) in optionscity" :key="index" :value="item.value" :label="label">{{
                            item.label }}</Option>
                    </Select> -->
              <jgcheckcity
                ref="checkcity"
                @cityvalue="cityvalue"
                v-model="area_code"
                name="network"
              ></jgcheckcity>
            </Col>
            <Col class="ivu-mb-16">
              <Select
                v-model="params.diagnosis_type"
                @on-change="formSize(1)"
                :max-tag-count="3"
                placeholder="诊断类型"
                filterable
                multiple
              >
                <Option
                  v-for="item in diagnosisList"
                  :value="item"
                  :key="item"
                  >{{ item }}</Option
                >
              </Select>
            </Col>
          </Row>
        </Col>
        <Col>
          <Row :gutter="16" type="flex" class="ivu-mb-16">
            <Col
              ><Button
                type="primary"
                :disabled="datatime[0] == '' ? true : false"
                :loading="prloading"
                @click="synchronous"
                >{{ `${prloading ? "正在同步" : "词性同步"}` }}</Button
              ></Col
            >
            <Col>
              <Button
                v-hasC="{
                  name: 'v1-patient-network-export',
                  flag: 'v1/patient/network/export',
                }"
                type="primary"
                :disabled="total === 0"
                :loading="buttonloading"
                @click="clickexport"
                >{{ buttonloading ? "正在导出" : "导出" }}</Button
              >
            </Col>
            <Col>
              <Button
                v-hasC="{
                  name: 'v1-patient-network-exportall',
                  flag: 'v1/patient/network/exportall',
                }"
                type="primary"
                :disabled="total === 0"
                :loading="reportloading"
                @click="clickexportAll"
                >{{ buttonloading ? "正在导出" : "导出所有" }}</Button
              >
            </Col>
            <Col>
              <Button type="primary" v-if="buttonbool" @click="clickexports"
                >下载</Button
              >
            </Col>
          </Row>
        </Col>
      </Row>
      <Table
        highlight-row
        :max-height="635"
        ref="table"
        :columns="columns"
        :loading="loading"
        :data="data"
        size="small"
      >
        <!-- 基本信息 -->
        <template slot-scope="{ row }" slot="info">
          <a @click="handleDetailPatient(row)">{{ row.info }}</a>
        </template>
        <!-- 城市 -->
        <template slot-scope="{ row }" slot="city_name">
          <div :title="row.city_name">
            {{ +row.city_name === 0 ? "" : row.city_name }}
          </div>
        </template>
        <!-- 接触时间 -->
        <template slot-scope="{ row }" slot="speak_time">
          <DatePicker
            :editable="false"
            v-if="parameters.id === row.id"
            :transfer="true"
            type="datetime"
            ref="producetime"
            format="yyyy-MM-dd HH:mm"
            @on-change="showTimePanel('producetime')"
            v-model="parameters.speak_time"
            placeholder="请选择"
          >
          </DatePicker>
          <span v-else>{{ row.speak_time }}</span>
        </template>
        <!-- 来源网址 -->
        <template slot-scope="{ row }" slot="source_url">
          <Input
            placeholder="请输入"
            type="text"
            v-model="parameters.source_url"
            v-if="parameters.id === row.id"
          ></Input>
          <Ellipsis
            v-if="parameters.id !== row.id && row.source_url"
            :transfer="true"
            :text="row.source_url"
            :length="30"
            tooltip
          ></Ellipsis>
          <!-- <Ellipsis v-else-if="parameters.id !== row.id && row.source_url" :transfer="true"
                              :text="row.source_url" :length="30" tooltip ></Ellipsis> -->
          <!-- <span v-else>{{ row.source_url }}</span> -->
        </template>
        <!-- 访问网址 -->
        <template slot-scope="{ row }" slot="visitor_url">
          <Input
            placeholder="请输入"
            type="text"
            v-model="parameters.visitor_url"
            v-if="parameters.id === row.id"
          ></Input>
          <Ellipsis
            v-if="parameters.id !== row.id && row.visitor_url"
            :transfer="true"
            :text="row.visitor_url"
            :length="30"
            tooltip
          ></Ellipsis>
          <!-- <Ellipsis v-else-if="parameters.id !== row.id && row.visitor_url" :transfer="true"
                              :text="row.visitor_url" :length="30" tooltip ></Ellipsis> -->
          <!-- <span v-else>{{ row.visitor_url }}</span> -->
        </template>
        <!-- 搜索词 -->
        <template slot-scope="{ row }" slot="search_key">
          <Input
            placeholder="请输入"
            type="text"
            v-model="parameters.search_key"
            v-if="parameters.id === row.id"
          ></Input>
          <!-- <Ellipsis v-else :transfer="true" :text="row.search_key" :length="8" tooltip /> -->
          <span v-else>{{ row.search_key }}</span>
        </template>
        <!-- 关键词 -->
        <template slot-scope="{ row }" slot="keyword">
          <Input
            placeholder="请输入"
            type="text"
            v-model="parameters.keyword"
            v-if="parameters.id === row.id"
          ></Input>
          <span v-else>{{ row.keyword }}</span>
        </template>
        <!-- 来源备注 -->
        <template slot-scope="{ row }" slot="source_remark">
          <Input
            placeholder="请输入"
            type="text"
            v-model="parameters.source_remark"
            v-if="parameters.id === row.id"
          ></Input>
          <Ellipsis
            v-if="parameters.id !== row.id && row.source_remark"
            :transfer="true"
            :text="row.source_remark"
            :length="18"
            tooltip
          ></Ellipsis>
          <!-- <Ellipsis v-else-if="
                        parameters.id !== row.id && row.source_remark
                    " :transfer="true" :text="row.source_remark" :length="18" tooltip ></Ellipsis> -->
          <!-- <span v-else>{{ row.source_remark }}</span> -->
        </template>
        <!-- 一级渠道 -->
        <template slot-scope="{ row }" slot="channel_id">
          <Select
            placeholder="请选择"
            :transfer="true"
            v-model="parameters.channel_id"
            v-if="parameters.id === row.id"
            @on-change="changechannel"
          >
            <Option
              v-for="(item, index) in channelList"
              :key="index"
              :value="item.id"
            >
              {{ item.label }}
            </Option>
          </Select>
          <span v-else>{{ row.channel }}</span>
        </template>
        <!-- 二级渠道 -->
        <template slot-scope="{ row }" slot="subdivided_channels_id">
          <Select
            placeholder="请选择"
            :transfer="true"
            v-model="parameters.subdivided_channels_id"
            v-if="parameters.id === row.id"
            clearable
          >
            <Option
              v-for="(item, index) in channelchildrenList"
              :key="index"
              :value="item.id"
            >
              {{ item.label }}
            </Option>
          </Select>
          <span v-else>{{ row.subdivided_channels }}</span>
        </template>
        <!-- 对话方式 -->
        <template slot-scope="{ row }" slot="dialog_mode">
          <Select
            placeholder="请选择"
            :transfer="true"
            v-model="parameters.dialog_mode_id"
            v-if="parameters.id === row.id"
          >
            <Option
              v-for="item in dialogmodeList"
              :key="item.value"
              :value="item.value"
            >
              {{ item.label }}
            </Option>
          </Select>
          <span v-else>{{ row.dialog_mode }}</span>
        </template>
        <!-- 对话状态 -->
        <template slot-scope="{ row }" slot="dialog_status">
          <Select
            placeholder="请选择"
            :transfer="true"
            v-model="parameters.dialog_status"
            v-if="parameters.id === row.id"
          >
            <Option value="1">正常</Option>
            <Option value="0">无效</Option>
          </Select>
          <span v-else>
            <Tag v-if="+row.dialog_status === 1" color="blue">正常</Tag>
            <Tag v-else color="red">无效</Tag>
          </span>
        </template>
        <!-- IP -->
        <template slot-scope="{ row }" slot="ip">
          <Input
            placeholder="请输入"
            type="text"
            v-model="parameters.source_ip"
            v-if="parameters.id === row.id"
          ></Input>
          <span v-else>{{ row.ip }}</span>
        </template>
        <!-- 词性 -->
        <template slot-scope="{ row }" slot="cixing_small">
          <Input
            placeholder="请输入"
            type="text"
            v-model="parameters.cixing_small"
            v-if="parameters.id === row.id"
          ></Input>
          <span v-else>{{ row.cixing_small }}</span>
        </template>
        <!-- 部位 -->
        <template slot-scope="{ row }" slot="body_parts_ids">
          <Form
            ref="create"
            :rules="rules"
            :label-width="row.diseases_name === '白癜风' ? 20 : 0"
            :model="parameters"
            v-if="parameters.id === row.id && !row.body_parts_ids[0]"
          >
            <FormItem
              prop="body_parts_ids"
              label=" "
              v-if="row.diseases_name === '白癜风'"
            >
              <Select
                placeholder="请选择"
                :transfer="true"
                multiple
                v-model="parameters.body_parts_ids"
              >
                <Option
                  :key="item.id"
                  :value="item.id"
                  v-for="item of body_parts"
                  >{{ item.label }}</Option
                >
              </Select>
            </FormItem>
            <FormItem v-else>
              <Select
                placeholder="请选择"
                :transfer="true"
                multiple
                v-model="parameters.body_parts_ids"
              >
                <Option
                  :key="item.id"
                  :value="item.id"
                  v-for="item of body_parts"
                  >{{ item.label }}</Option
                >
              </Select>
            </FormItem>
          </Form>
          <span v-else>
            <template v-for="(item, index) in row.body_parts_names">
              <Tag :key="index" v-if="item">{{ item }}</Tag>
            </template>
          </span>
        </template>
        <!-- 留言信息 -->
        <template slot-scope="{ row }" slot="leave_msg">
          <Input
            placeholder="请输入"
            type="text"
            v-model="parameters.leave_msg"
            v-if="parameters.id === row.id"
          ></Input>
          <Ellipsis
            v-if="parameters.id !== row.id && row.leave_msg"
            :transfer="true"
            :text="row.leave_msg"
            :length="8"
            tooltip
          ></Ellipsis>
          <!-- <Ellipsis v-else-if="parameters.id !== row.id && row.leave_msg" :transfer="true" :text="row.leave_msg" :length="8" tooltip ></Ellipsis> -->
          <!-- <span v-else>{{ row.leave_msg }}</span> -->
        </template>
        <template slot-scope="{ row }" slot="state">
          <Tag v-if="row.status_name === '无效'" color="red">{{
            row.status_name
          }}</Tag>
          <Tag v-else-if="row.status_name === '跟进中'" color="volcano">{{
            row.status_name
          }}</Tag>
          <Tag v-else-if="row.status_name === '预约'" color="cyan">{{
            row.status_name
          }}</Tag>
          <Tag v-else-if="row.status_name === '到诊'" color="green">{{
            row.status_name
          }}</Tag>
          <Tag v-else-if="row.status_name === '老患者到诊'" color="magenta">{{
            row.status_name
          }}</Tag>
          <Tag v-else-if="row.status_name === '有意向'" color="blue">{{
            row.status_name
          }}</Tag>
          <Tag v-else-if="row.status_name === '未开口'" color="purple">{{
            row.status_name
          }}</Tag>
          <Tag v-else-if="row.status_name" color="orange">{{
            row.status_name
          }}</Tag>
        </template>
        <!-- 操作 -->
        <template slot="operation" slot-scope="{ row }">
          <div v-if="parameters.id === row.id">
            <Button
              type="success"
              size="small"
              :loading="loadings"
              @click="handleSava(row)"
              class="ivu-mr-8"
              >保存</Button
            >
            <Button type="default" size="small" @click="handleSavacancel"
              >取消</Button
            >
          </div>
          <div v-else>
            <Button
              v-hasC="{
                name: 'patient-network-update',
                flag: 'v1/patient/network/update',
              }"
              type="primary"
              size="small"
              @click="handleEdit(row)"
              >编辑</Button
            >
          </div>
        </template>
      </Table>
      <div class="ivu-mt ivu-text-center">
        <Page
          show-total
          show-elevator
          show-sizer
          :total="total"
          :current.sync="params.page"
          :page-size="params.pageSize"
          :page-size-opts="pageOpts"
          @on-change="formSize"
          @on-page-size-change="formChangePage"
        ></Page>
      </div>
    </Card>
    <patient-detail
      ref="patientDetail"
      :btnShow="btnShow"
      @cancelDrawer="askData"
      @askData="askData"
    ></patient-detail>
  </div>
</template>
<script>
import dayjs from "dayjs";
import { mapState, mapMutations } from "vuex";
import {
  networkselectinfo,
  networklist,
  networkupdate,
  networkexport,
  patientindexsearchcity,
  updatepatientCixing,
} from "@/api/hqapi";
import patientDetail from "@/components/patientDetail";
// import jgcheckcity from "@/components/checkcity";
import Setting from "@/setting";
export default {
  name: "network",
  components: { patientDetail },
  computed: {
    ...mapState("power/export", ["buttonloading", "exporturl", "buttonbool"]),
  },
  data() {
    return {
      loading: false,
      reportloading: false,
      datatime: [new Date(), new Date()],
      dayDate: 1,
      rules: {
        body_parts_ids: [
          {
            required: true,
            type: "array",
            message: "请选择部位",
            trigger: "change",
          },
        ],
      },
      loadings: false,
      options: {
        disabledDate(date) {
          return date && date.valueOf() > Date.now();
        },
      },
      btnShow: [
        {
          name: "patient-index-sub2",
          flag: "v1/patient/index/sub",
        },
        {
          name: "patient-index-edit-remark1",
          flag: "v1/patient/index/edit-remark",
        },
        {
          name: "patient-index-update2",
          flag: "v1/patient/index/update",
        },
        {
          name: "patient-callback-callback-common-list3",
          flag: "v1/patient/callback/callback-common-list",
        },
        {
          name: "patient-index-edit-tags5",
          flag: "v1/patient/index/edit-tags",
        },
        {
          name: "patient-index-edit-tags4",
          flag: "v1/patient/index/edit-tags",
        },
      ],
      data: [],
      patientstatusList: [],
      channelList: [],
      channelchildrenList: [],
      dialogmodeList: [],
      diseaseslist: [],
      diagnosisList: [],
      columns: [
        {
          title: "基本信息",
          resizable: true,
          key: "info",
          slot: "info",
          fixed: "left",
          width: 130,
        },
        {
          title: "登记时间",
          resizable: true,
          key: "created_at",
          width: 135,
        },
        {
          title: "接触时间",
          resizable: true,
          slot: "speak_time",
          width: 190,
        },
        {
          title: "归属人",
          resizable: true,
          key: "member_names",
          width: 120,
        },
        {
          title: "城市",
          resizable: true,
          key: "city_name",
          slot: "city_name",
          width: 200,
        },
        {
          title: "诊断类型",
          resizable: true,
          key: "diagnosis_type",
          width: 160,
        },
        {
          title: "疾病类型",
          resizable: true,
          key: "diseases_name",
          width: 100,
        },
        {
          title: "部位",
          resizable: true,
          slot: "body_parts_ids",
          minWidth: 100,
        },
        {
          title: "状态",
          resizable: true,
          key: "status_name",
          slot: "state",
          width: 100,
        },
        {
          title: "对话方式",
          resizable: true,
          key: "dialog_mode",
          slot: "dialog_mode",
          minWidth: 140,
        },
        {
          title: "对话状态",
          resizable: true,
          key: "dialog_status",
          slot: "dialog_status",
          minWidth: 140,
        },
        {
          title: "来源备注",
          resizable: true,
          slot: "source_remark",
          width: 160,
          ellipsis: true,
          tooltip: true,
        },
        {
          title: "唯一身份",
          resizable: true,
          key: "visitor_uid",
          width: 160,
          ellipsis: true,
          tooltip: true,
        },
        {
          title: "搜索词",
          resizable: true,
          slot: "search_key",
          width: 160,
          ellipsis: true,
          tooltip: true,
        },
        {
          title: "关键词",
          resizable: true,
          slot: "keyword",
          width: 160,
          ellipsis: true,
          tooltip: true,
        },
        {
          title: "词性大类",
          // resizable: true,
          key: "word_class",
          width: 160,
        },
        {
          title: "词性",
          resizable: true,
          slot: "cixing_small",
          width: 160,
        },
        {
          title: "一级渠道",
          resizable: true,
          key: "channel_id",
          slot: "channel_id",
          width: 120,
        },
        {
          title: "二级渠道",
          resizable: true,
          key: "subdivided_channels_id",
          slot: "subdivided_channels_id",
          width: 120,
        },
        {
          title: "访问网址",
          resizable: true,
          slot: "visitor_url",
          width: 220,
        },
        {
          title: "来源网址",
          resizable: true,
          slot: "source_url",
          width: 220,
        },
        {
          title: "IP",
          resizable: true,
          key: "ip",
          slot: "ip",
          width: 160,
        },
        {
          title: "IP归属地",
          resizable: true,
          key: "ip_address",
          width: 160,
        },
        {
          title: "留言信息",
          resizable: true,
          key: "leave_msg",
          slot: "leave_msg",
          minWidth: 160,
          ellipsis: true,
          tooltip: true,
        },
        {
          title: "咨询备注",
          resizable: true,
          key: "remark",
          width: 160,
          ellipsis: true,
          tooltip: true,
        },
        {
          title: "操作",
          resizable: true,
          slot: "operation",
          fixed: "right",
          width: 135,
        },
      ],
      params: {
        area_code: "",
        page: 1,
        pageSize: 10,
        patient_status_id: "",
        dialog_mode_id: "",
        dialog_status: "",
        source_channel_id: [],
        // start_date: "",
        // end_date: "",
        speak_start: "",
        speak_end: "",
        keyword: "",
        patient_diseases_id: "",
        diagnosis_type: "",
      },
      parameters: {
        id: undefined,
        dialog_mode_id: "",
        dialog_status: "",
        speak_time: "",
        source_url: "",
        visitor_url: "",
        search_key: "",
        keyword: "",
        source_remark: "",
        channel_id: "",
        subdivided_channels_id: "",
        source_ip: "",
        leave_msg: "",
        word_class: "",
        body_parts_ids: [],
        cixing_small: "",
      },
      body_parts: [],
      total: 0,
      loadingcity: false,
      optionscity: [],
      timer: "",
      exportloading: false,
      area_code: [],
      exporttext: "导出",
      pageOpts: [10, 15, 20, 30, 50], // 分页每页数量
      prloading: false,
    };
  },
  methods: {
    ...mapMutations("power/export", [
      "changeLoading",
      "changebool",
      "changeUrl",
    ]),

    cityvalue(city) {
      this.area_code = city;
      this.params.area_code = city.join(",");
      this.params.page = 1;
      this.askData();
    },
    // 初始化
    initial() {
      networkselectinfo().then((res) => {
        this.channelList = res.source_channel;
        this.patientstatusList = res.patient_status;
        (this.diseaseslist = res.diseases),
          (this.dialogmodeList = res.dialog_mode);
        this.body_parts = res.body_parts;
      });
      this.changeradio(this.dayDate);
    },
    // 请求数据
    askData() {
      this.loading = true;
      let params = JSON.parse(JSON.stringify(this.params));
      params.source_channel_id = params.source_channel_id.join(",");
      // params.patient_diseases_id = params.patient_diseases_id.join(',')
      this.$store.commit("admin/account/changeCloseRefresh", false);
      networklist(params).then((res) => {
        this.diagnosisList = res.condition.diagnosis_type;
        let lists = res.list.map((ee) => {
          let member_names = +ee.patient_data_type == 0 ? ee.member_name : "";
          return {
            ...ee,
            member_names,
          };
        });
        this.data = lists;
        this.total = res.total;
        this.loading = false;
        this.handleSavacancel();
      });
    },
    /* @函数功能: 分页 */
    formSize(e) {
      this.params.page = e;
      this.askData();
    },
    /* @函数功能: 每页数量 */
    formChangePage(e) {
      this.params.pageSize = e;
      this.askData();
    },
    // 词性同步
    synchronous() {
      this.prloading = true;
      const params = {
        start_time: this.datatime[0]
          ? dayjs(this.datatime[0]).format("YYYY-MM-DD")
          : "",
        end_time: this.datatime[1]
          ? dayjs(this.datatime[1]).format("YYYY-MM-DD")
          : "",
      };
      updatepatientCixing(params)
        .then((res) => {
          this.$Message.success("词性同步成功");
          this.prloading = false;
          this.askData();
        })
        .catch(() => {
          this.prloading = false;
        });
    },
    handleEdit(row) {
      this.parameters.id = row.id;
      this.parameters.speak_time = row.speak_time;
      this.parameters.dialog_mode_id = row.dialog_mode_id;
      this.parameters.dialog_status = row.dialog_status;
      this.parameters.source_url = row.source_url;
      this.parameters.visitor_url = row.visitor_url;
      this.parameters.search_key = row.search_key;
      this.parameters.keyword = row.keyword;
      this.parameters.source_remark = row.source_remark;
      this.parameters.channel_id = row.channel_id;
      this.parameters.subdivided_channels_id = row.subdivided_channels_id;
      this.parameters.source_ip = row.ip;
      this.parameters.cixing_small = row.cixing_small;
      this.parameters.leave_msg = row.leave_msg;

      this.parameters.body_parts_ids = [];
      this.parameters.word_class = row.word_class;
      for (let item of row.body_parts_ids) {
        if (item) {
          this.parameters.body_parts_ids.push(item);
        }
      }
      // this.parameters.body_parts_ids = row.body_parts_ids;
      this.changechannel();
    },
    showTimePanel(refName) {
      this.$refs[refName].onSelectionModeChange("time");
    },
    handleSava(row) {
      // if(this.parameters.channel_id == 0) {
      //     this.$Message.error('请选择一级渠道');
      // }else if(this.parameters.subdivided_channels_id == 0) {
      //     this.$Message.error('请选择二级渠道');
      // }else {
      if (row.diseases_name === "白癜风" && !row.body_parts_ids[0]) {
        this.$refs.create.validate((valid) => {
          if (valid) {
            this.loadings = true;
            let parameters = JSON.parse(JSON.stringify(this.parameters));
            parameters.body_parts_ids = this.parameters.body_parts_ids.join(
              ","
            );
            networkupdate(parameters)
              .then((res) => {
                let datas = [];
                let that = res[0];
                for (let item of this.data) {
                  if (+item.id === +that.id) {
                    datas.push(that);
                  } else {
                    datas.push(item);
                  }
                }
                this.data = [];
                this.data = datas;
                this.handleSavacancel();
                this.$refs.create.resetFields();
                this.loadings = false;
                this.askData();
              })
              .catch(() => {
                this.loadings = false;
              });
          } else {
            this.$Message.error("病种白癜风,部位必填");
          }
        });
      } else {
        this.loadings = true;
        let parameters = JSON.parse(JSON.stringify(this.parameters));
        parameters.body_parts_ids = this.parameters.body_parts_ids.join(",");
        this.logs(this.parameters.body_parts_ids);
        parameters.speak_time = dayjs(this.parameters.speak_time).format(
          "YYYY-MM-DD HH:mm"
        );
        networkupdate(parameters)
          .then((res) => {
            let datas = [];
            let that = res[0];
            for (let item of this.data) {
              if (+item.id === +that.id) {
                datas.push(that);
              } else {
                datas.push(item);
              }
            }
            this.data = [];
            this.data = datas;
            this.handleSavacancel();
            this.loadings = false;
            this.askData();
          })
          .catch(() => {
            this.loadings = false;
          });
      }
      // }
    },
    handleSavacancel() {
      this.parameters = {
        id: undefined,
        speak_time: "",
        source_url: "",
        dialog_mode_id: "",
        dialog_status: "",
        visitor_url: "",
        search_key: "",
        keyword: "",
        source_remark: "",
        channel_id: "",
        subdivided_channels_id: "",
        source_ip: "",
        leave_msg: "",

        word_class: "",
        body_parts_ids: [],
      };
      this.channelchildrenList = [];
    },
    handleDetailPatient(row) {
      this.$refs.patientDetail.handleOpen(row);
    },
    changeradio(data) {
      this.datatime = [];
      if (data === 0) {
        this.datatime[0] = new Date(
          dayjs()
            .subtract(1, "day")
            .format("YYYY-MM-DD")
        );
        this.datatime[1] = new Date(
          dayjs()
            .subtract(1, "day")
            .format("YYYY-MM-DD")
        );
      } else if (data === 1) {
        this.datatime[0] = new Date();
        this.datatime[1] = new Date();
      }
      this.askDatachange();
    },
    changeDate() {
      if (
        dayjs(this.datatime[0]).format("YYYY-MM-DD") ===
        dayjs(this.datatime[1]).format("YYYY-MM-DD")
      ) {
        if (
          dayjs(this.datatime[0]).format("YYYY-MM-DD") ===
          dayjs().format("YYYY-MM-DD")
        ) {
          this.dayDate = 1;
        } else if (
          dayjs(this.datatime[0]).format("YYYY-MM-DD") ===
          dayjs()
            .subtract(1, "day")
            .format("YYYY-MM-DD")
        ) {
          this.dayDate = 0;
        } else {
          this.dayDate = -1;
        }
      } else {
        this.dayDate = -1;
      }
      let timer = ["", ""];
      if (JSON.stringify(this.datatime) !== JSON.stringify(["", ""])) {
        timer = [
          this.$Date(this.datatime[0]).format("YYYY-MM-DD"),
          this.$Date(this.datatime[1]).format("YYYY-MM-DD"),
        ];
      }
      this.storage.set("netwoek", timer);
      this.askDatachange();
    },
    askDatachange() {
      this.params.page = 1;
      // this.params.start_date = this.datatime[0];
      // this.params.end_date = this.datatime[1];

      this.params.speak_start = this.datatime[0];
      this.params.speak_end = this.datatime[1];
      this.askData();
    },
    askDatas() {
      if (JSON.stringify(this.datatime) !== JSON.stringify(["", ""])) {
        let timer = [
          this.$Date(this.datatime[0]).format("YYYY-MM-DD"),
          this.$Date(this.datatime[1]).format("YYYY-MM-DD"),
        ];
        this.storage.set("netwoek", timer);
        this.datatime = ["", ""];
      }
      this.dayDate = -1;
      this.params.page = 1;
      this.params.pageSize = 10;
      this.params.patient_status_id = "";
      this.params.dialog_mode_id = "";
      this.params.dialog_status = "";
      this.params.area_code = "";
      this.askDatachange();
    },
    askDatass() {
      this.params.page = 1;
      this.params.pageSize = 10;
      this.params.patient_status_id = "";
      this.params.dialog_mode_id = "";
      this.params.dialog_status = "";
      this.params.area_code = "";
      this.dayDate = -1;
      if (
        JSON.stringify(this.storage.get("netwoek")) !== JSON.stringify(["", ""])
      ) {
        this.datatime = this.storage.get("netwoek");
        // this.params.start_date = this.datatime[0];
        // this.params.end_date = this.datatime[1];

        this.params.speak_start = this.datatime[0];
        this.params.speak_end = this.datatime[1];
      }
      this.askDatachange();
    },
    changechannel() {
      this.channelchildrenList = [];
      for (let item of this.channelList) {
        if (this.parameters.channel_id * 1 === item.id * 1) {
          this.channelchildrenList = item.children;
        }
      }
    },
    clickexport() {
      // this.exportloading = true
      this.changeLoading(true);
      this.exporttext = "正在导出";
      let config = {
        patient_diseases_id: this.params.patient_diseases_id,
        patient_status_id: this.params.patient_status_id,
        dialog_mode_id: this.params.dialog_mode_id,
        dialog_status: this.params.dialog_status,
        source_channel_id: this.params.source_channel_id.join(","),
        // start_date: this.params.start_date,
        // end_date: this.params.end_date,
        speak_start: this.params.speak_start,
        speak_end: this.params.speak_end,
        keyword: this.params.keyword,
        area_code: this.params.area_code,
        diagnosis_type: this.params.diagnosis_type,
        project_id: localStorage.getItem("currentProject"),
      };
      networkexport(config)
        .then((res) => {
          this.exportloading = false;
          this.exporttext = "导出";
          // this.buttonbool = true
        })
        .catch(() => {
          this.exportloading = false;
          this.exporttext = "导出";
        });
    },
    clickexportAll() {
      this.reportloading = true;
      let config = {
        patient_diseases_id: this.params.patient_diseases_id,
        patient_status_id: this.params.patient_status_id,
        dialog_mode_id: this.params.dialog_mode_id,
        dialog_status: this.params.dialog_status,
        source_channel_id: this.params.source_channel_id.join(","),
        // start_date: this.params.start_date,
        // end_date: this.params.end_date,
        speak_start: this.params.speak_start,
        speak_end: this.params.speak_end,
        keyword: this.params.keyword,
        diagnosis_type: this.params.diagnosis_type,
        area_code: this.params.area_code,
        project_id: 0,
      };
      networkexport(config)
        .then((res) => {
          this.reportloading = false;
          // this.buttonbool = true
        })
        .catch(() => {
          this.reportloading = false;
        });
    },
    clickexports() {
      let urltitle = Setting.apiBaseURL;
      let url = `${urltitle}/${this.exporturl}`;
      window.open(url);
    },
    remoteMethod(query) {
      clearTimeout(this.timer);
      if (query !== "") {
        let reg = new RegExp("[\\u4E00-\\u9FFF]+", "g");
        if (parseFloat(query).toString() !== "NaN") {
          return;
        }
        if (!reg.test(query)) {
          return;
        }
        this.loadingcity = true;
        return new Promise((resolve) => {
          this.timer = setTimeout(() => {
            patientindexsearchcity({
              keywords: query,
            }).then((res) => {
              if (res.list && res.list.length > 0) {
                let list = [];
                for (let item of res.list) {
                  list.push({
                    value: item.value,
                    label: item.label,
                  });
                }
                this.optionscity = list;
              }
              resolve(res.data);
            });
            this.loadingcity = false;
          }, 200);
        });
      }
    },
  },

  mounted() {
    this.initial();
  },
};
</script>
<style scoped>
/deep/.ivu-form-item {
  margin-bottom: 0 !important;
}
</style>
